<?php

function EncryptPw($password)
{
  if($password == "")
    return $password;
  
  $passwordHash = hash("sha512",$password);
  return $passwordHash;
}

function ConvertDateTime($datetime, $localTimeFormat) {
  $format = "";
  if($localTimeFormat)
    $format="d.m.Y H:i:s";
  else
    $format="Y-m-d H:i:s";
    
  if($datetime == null)
    return date($format);
  else
    return date($format, strtotime($datetime));
}

function ConvertDateTimeToDate($datetime, $localTimeFormat){
    $format = "";
      if($localTimeFormat)
      $format="d.m.Y";
      else
      $format="Y-m-d";
        
      if($datetime == null)
        return date($format);
      else
        return date($format, strtotime($datetime));
}

function ConvertDate($date, $localTimeFormat) {
    $format = "";
    if($localTimeFormat){
        $format="d.m.Y";
    }
    else {
        $format="Y-m-d";
    }
    
    if($date == null){
        return date($format);
    }
    else{
        return date($format, strtotime($date));
    }
}

function alertLevel($alertText)
{
      if(strpos($alertText, "fehlgeschlagen")!==false || strpos($alertText, "vorhanden")!==false || strpos($alertText, "gefunden")!==false)
      {
        $imgChange='<img src="../design/pictures/error.png" width="16" alt="X"/>&nbsp;';
      }
      else if(strpos($alertText, "Aenderung")!==false)
      {
        $imgChange='<img src="../design/pictures/warning.png" width="16" alt="!"/>&nbsp;';
      }
      else
      {
        $imgChange='<img src="../design/pictures/exclamation.png" width="16" alt=""/>&nbsp;';
      }
      return $imgChange;
}

function sanitizeOutputString($text) {
  $search = array ("\r\n", "\n"  , "\r"  ,"ü"     ,"Ü"     ,"ä"     ,"Ä"     ,"ö"     ,"Ö");
  $replace = array("<br>", "<br>", "<br>","&uuml;","&Uuml;","&auml;","&Auml;","&ouml;","&Ouml;");
  return str_replace($search, $replace, $text);
}

function sanitizeInputStringBR($text) {
  $search = array ("\r\n", "\n"  , "\r");
  $replace = array("<br>", "<br>", "<br>");
  return str_replace($search, $replace, $text);
}

function sanitizeInputString($text)
{
    return html_entity_decode(htmlentities(sanitizeInputStringBR($text))); 
}
